﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;
using BLL.Access;
using Platform.Http;
using Web.Class;
using Platform.Common;
using DevExpress.Web;
using System.Text;
using System.Data;

namespace Web.Controls.LAIHAN
{
    public partial class UCLHGaiHuJHXX : System.Web.UI.UserControl,IUCLHOperate
    {
        #region 属性
        public string LaiHanYongHuH
        {
            get;
            set;
        }
        #endregion

        #region 变量
        /// <summary>
        /// 原计划信息BLL
        /// </summary>
        YS_JH_YUANJIHUABLL BllYuanJH = new YS_JH_YUANJIHUABLL();
        /// <summary>
        /// 调整计划BLL
        /// </summary>
        YS_JH_TIAOZHENGJHBLL BllTiaoZhengJH = new YS_JH_TIAOZHENGJHBLL();
        /// <summary>
        /// 存储过程BLL
        /// </summary>
        SpHelper _sphelper = new SpHelper();
        /// <summary>
        /// 用户信息BLL
        /// </summary>
        YS_YG_YONGHUXXBLL BllYongHuXX = new YS_YG_YONGHUXXBLL();
        /// <summary>
        /// 用户调整BLL
        /// </summary>
        YS_LH_YONGHUTZProcess BllYongHuTZ = new YS_LH_YONGHUTZProcess();

        #endregion

        #region 事件
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               
            }
        }

        #endregion

        #region 方法
        /// <summary>
        /// 根据用户号查询计划信息
        /// </summary>
        /// <param name="yonghuh"></param>
        private void BindValue(string yonghuh)
        {
            LaiHanYongHuH = yonghuh;
            int waterYM = BusinessTool.GetWaterYM();
            if (LaiHanYongHuH != null && LaiHanYongHuH.Length > 0)
            {                
                string y = waterYM.ToString().Substring(0,4);

                string where = " S_YONGHUH='{0}' and I_Y={1}  ";
                where = string.Format(where,LaiHanYongHuH,y);

                DataTable dtY = BllYuanJH.SelectYS_JH_YUANJIHUAsDynamic(where,"",null);

                DataTable dtT = BllTiaoZhengJH.SelectYS_JH_TIAOZHENGJHsDynamic(where+" and I_PTYPE=8 ", "", null);
                if (dtT != null && dtT.Rows.Count > 0)
                { 
                    DataRow dr =dtT.Rows[0];
                    txtYuanJiH1.Text = dr["I_M1"].ToString();
                    txtYuanJiH2.Text = dr["I_M2"].ToString();
                    txtYuanJiH3.Text = dr["I_M3"].ToString();
                    txtYuanJiH4.Text = dr["I_M4"].ToString();
                    txtYuanJiH5.Text = dr["I_M5"].ToString();

                    txtYuanJiH6.Text = dr["I_M6"].ToString();
                    txtYuanJiH7.Text = dr["I_M7"].ToString();
                    txtYuanJiH8.Text = dr["I_M8"].ToString();
                    txtYuanJiH9.Text = dr["I_M9"].ToString();
                    txtYuanJiH10.Text = dr["I_M10"].ToString();

                    txtYuanJiH11.Text = dr["I_M11"].ToString();
                    txtYuanJiH12.Text = dr["I_M12"].ToString();
                    txtYuanJiH13.Text = (Convert.ToInt32(dr["I_M1"]) + Convert.ToInt32(dr["I_M2"]) + Convert.ToInt32(dr["I_M3"])
                        + Convert.ToInt32(dr["I_M4"]) + Convert.ToInt32(dr["I_M5"]) + Convert.ToInt32(dr["I_M6"])
                        + Convert.ToInt32(dr["I_M7"]) + Convert.ToInt32(dr["I_M8"]) + Convert.ToInt32(dr["I_M9"])
                        + Convert.ToInt32(dr["I_M10"]) + Convert.ToInt32(dr["I_M11"]) + Convert.ToInt32(dr["I_M12"])).ToString();

                }
                else if (dtY != null && dtY.Rows.Count > 0)
                {
                    DataRow dr = dtY.Rows[0];
                    txtYuanJiH1.Text = dr["I_M1"].ToString();
                    txtYuanJiH2.Text = dr["I_M2"].ToString();
                    txtYuanJiH3.Text = dr["I_M3"].ToString();
                    txtYuanJiH4.Text = dr["I_M4"].ToString();
                    txtYuanJiH5.Text = dr["I_M5"].ToString();

                    txtYuanJiH6.Text = dr["I_M6"].ToString();
                    txtYuanJiH7.Text = dr["I_M7"].ToString();
                    txtYuanJiH8.Text = dr["I_M8"].ToString();
                    txtYuanJiH9.Text = dr["I_M9"].ToString();
                    txtYuanJiH10.Text = dr["I_M10"].ToString();

                    txtYuanJiH11.Text = dr["I_M11"].ToString();
                    txtYuanJiH12.Text = dr["I_M12"].ToString();
                    txtYuanJiH13.Text = (Convert.ToInt32(dr["I_M1"]) + Convert.ToInt32(dr["I_M2"]) + Convert.ToInt32(dr["I_M3"])
                        + Convert.ToInt32(dr["I_M4"]) + Convert.ToInt32(dr["I_M5"]) + Convert.ToInt32(dr["I_M6"])
                        + Convert.ToInt32(dr["I_M7"]) + Convert.ToInt32(dr["I_M8"]) + Convert.ToInt32(dr["I_M9"])
                        + Convert.ToInt32(dr["I_M10"]) + Convert.ToInt32(dr["I_M11"]) + Convert.ToInt32(dr["I_M12"])).ToString();
                }
                else
                {
                    txtYuanJiH1.Text = "0";
                    txtYuanJiH2.Text = "0";
                    txtYuanJiH3.Text = "0";
                    txtYuanJiH4.Text = "0";
                    txtYuanJiH5.Text = "0";

                    txtYuanJiH6.Text = "0";
                    txtYuanJiH7.Text = "0";
                    txtYuanJiH8.Text = "0";
                    txtYuanJiH9.Text = "0";
                    txtYuanJiH10.Text = "0";

                    txtYuanJiH11.Text = "0";
                    txtYuanJiH12.Text = "0";
                    txtYuanJiH13.Text = "0";
                }
                int? syl_sy, yjh;
                DataSet ds = new SpHelper().P_YS_LH_YONGHUYSSJCX(waterYM / 100, waterYM % 100, yonghuh, out yjh, out syl_sy);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    txtShiYong1.Text = dr["IM1"].ToString();
                    txtShiYong2.Text = dr["IM2"].ToString();
                    txtShiYong3.Text = dr["IM3"].ToString();
                    txtShiYong4.Text = dr["IM4"].ToString();
                    txtShiYong5.Text = dr["IM5"].ToString();

                    txtShiYong6.Text = dr["IM6"].ToString();
                    txtShiYong7.Text = dr["IM7"].ToString();
                    txtShiYong8.Text = dr["IM8"].ToString();
                    txtShiYong9.Text = dr["IM9"].ToString();
                    txtShiYong10.Text = dr["IM10"].ToString();

                    txtShiYong11.Text = dr["IM11"].ToString();
                    txtShiYong12.Text = dr["IM12"].ToString();
                    txtShiYong13.Text = (Convert.ToInt32(dr["IM1"]) + Convert.ToInt32(dr["IM2"]) + Convert.ToInt32(dr["IM3"])
                        + Convert.ToInt32(dr["IM4"]) + Convert.ToInt32(dr["IM5"]) + Convert.ToInt32(dr["IM6"])
                        + Convert.ToInt32(dr["IM7"]) + Convert.ToInt32(dr["IM8"]) + Convert.ToInt32(dr["IM9"])
                        + Convert.ToInt32(dr["IM10"]) + Convert.ToInt32(dr["IM11"]) + Convert.ToInt32(dr["IM12"])).ToString();
                }
                /*
                DataSet ds = new SpHelper().P_YS_LH_YONGHUYSSJCX(Convert.ToInt32(y), null, LaiHanYongHuH, 1);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    
                    txtShiYong1.Text = dr["IM1"].ToString();
                    txtShiYong2.Text = dr["IM2"].ToString();
                    txtShiYong3.Text = dr["IM3"].ToString();
                    txtShiYong4.Text = dr["IM4"].ToString();
                    txtShiYong5.Text = dr["IM5"].ToString();

                    txtShiYong6.Text = dr["IM6"].ToString();
                    txtShiYong7.Text = dr["IM7"].ToString();
                    txtShiYong8.Text = dr["IM8"].ToString();
                    txtShiYong9.Text = dr["IM9"].ToString();
                    txtShiYong10.Text = dr["IM10"].ToString();

                    txtShiYong11.Text = dr["IM11"].ToString();
                    txtShiYong12.Text = dr["IM12"].ToString();
                    txtShiYong13.Text = (Convert.ToInt32(dr["IM1"]) + Convert.ToInt32(dr["IM2"]) + Convert.ToInt32(dr["IM3"])
                        + Convert.ToInt32(dr["IM4"]) + Convert.ToInt32(dr["IM5"]) + Convert.ToInt32(dr["IM6"])
                        + Convert.ToInt32(dr["IM7"]) + Convert.ToInt32(dr["IM8"]) + Convert.ToInt32(dr["IM9"])
                        + Convert.ToInt32(dr["IM10"]) + Convert.ToInt32(dr["IM11"]) + Convert.ToInt32(dr["IM12"])).ToString();
                }
                txtXinJH1.Text = txtYuanJiH1.Text;
                txtXinJH2.Text = txtYuanJiH2.Text;
                txtXinJH3.Text = txtYuanJiH3.Text;
                txtXinJH4.Text = txtYuanJiH4.Text;
                txtXinJH5.Text = txtYuanJiH5.Text;

                txtXinJH6.Text = txtYuanJiH6.Text;
                txtXinJH7.Text = txtYuanJiH7.Text;
                txtXinJH8.Text = txtYuanJiH8.Text;
                txtXinJH9.Text = txtYuanJiH9.Text;
                txtXinJH10.Text = txtYuanJiH10.Text;

                txtXinJH11.Text = txtYuanJiH11.Text;
                txtXinJH12.Text = txtYuanJiH12.Text;
                txtXinJH13.Text = txtYuanJiH13.Text;
                */
               
           
            }
        }

        

        public void InitControl()
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// 验证
        /// </summary>
        /// <returns></returns>
        public ValidateRS Validate()
        {
            ValidateRS rs = new ValidateRS();

            rs.Msg = "";
            rs.IsSuccess = true;
            return rs;
        }
        /// <summary>
        /// 清空数据
        /// </summary>
        public void ClearInfo()
        {
            foreach (Control c in this.Controls)
            {
                if (c is DevExpress.Web.ASPxTextBox)
                {
                    DevExpress.Web.ASPxTextBox txt = c as DevExpress.Web.ASPxTextBox;
                    txt.Text = "";
                }
            }
        }
        /// <summary>
        /// 加载信息
        /// </summary>
        /// <param name="laihanxx"></param>
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            BindValue(laihanxx.S_YONGHUBH);
            DataSet ds = this._sphelper.P_YS_LHGETINFODETAIL(laihanxx.S_LAIHANBH, (int)laihanxx.I_LAIHANLX);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                this.txtShouLiRQ.Text = Convert.ToDateTime(dr["D_SHOULIRQ"]).ToString("yyyy-MM-dd");
                this.txtYeWuY.Text = dr["S_YWY"].ToString();
            }
            DataTable UserDt = BllYongHuXX.SelectYS_YG_YONGHUXXesDynamic(" S_YONGHUH='"+laihanxx.S_YONGHUBH+"' and i_leixing=0 and i_jlzt=0 ","",null);
            if (UserDt != null && UserDt.Rows.Count > 0)
            {
                txtYongHuM.Text = UserDt.Rows[0]["S_YONGHUM"].ToString();
            }
            string TiaoZheng = " S_LAIHANBH='{0}' and S_YuanYongHuH='{1}' and i_jlzt=0 ";
            TiaoZheng = string.Format(TiaoZheng,laihanxx.S_LAIHANBH,laihanxx.S_YONGHUBH);
            DataTable dt = BllYongHuTZ.SelectYS_LH_YONGHUTZsDynamic(TiaoZheng,"",null);
            if (dt != null && dt.Rows.Count > 0)
            {
                txtYongHuHNEW.Text = dt.Rows[0]["S_YONGHUH"].ToString();
            }
        }
        #endregion
    }
}